var currentIndex;
$(document).ready(function(){
	selectCard();
	initUser();
	getUserInfo();
});
//切换选择卡
function selectCard(){
	$(".tree-nav li").click(function(){
		$(this).addClass("active").append('<span class="active-dot"></span>').siblings().removeClass("active").children("span").remove();
		$(".content-area .content-item").eq($(this).index()).show().siblings().hide();
		clickCard($(this).index());//切换选择卡，右边内容栏初始化
	});
}
//点击不同的选择卡，采取不同的初始化动作
function clickCard(index){
	switch (index){
		case 0:
			getUserInfo();
			break;
		case 1:
			initArticle();
			break;
		case 2:
			initaq();
			break;
		case 3:
			initNote();
			break;
		case 4:
			getFollow();
			break;
		case 5:
			initColletionArticle();
			break;
		case 6:
			initSixin();
			break;
		case 7:
			initLeaveWord();
			break;
		default:
			break;
	}
}
//获取cookie的user，全局变量
var user;
function getUserInfo(){
	var url = "/HyperIT/userdetail/getUserInfo";
	var parm = "userDetail_id="+user.id;
	$.post(url,parm,function(data){
		if(data.serviceResult){
			var userdetail = data.resultParm.userDetail;
			$("#name").text(userdetail.name);
			if(!userdetail.sex){
				$("#sex").text("男");
			}else{
				$("#sex").text("女");
			}
			$("#level").text("Lv."+userdetail.level);
			$("#hb").text(userdetail.hb);
			$("#ts").text(userdetail.total_sign+"天");
			$("#fans").text(userdetail.fans);
			$("#article").text(userdetail.article+"篇");
			$("#accept").text(userdetail.accept+"次");
			$("#note").text(userdetail.note+"篇");
			$("#city").text(userdetail.city);
			$("#position").text(userdetail.position_name);
			$("#createtime").text(userdetail.createtime.substr(0,16));
			var skillList = userdetail.skill.split(" ");
			$("#skill").children("span").remove();
			for(var i = 0; i<skillList.length; i++){
				$("#skill").append('<span>'+skillList[i]+'</span>');
			}
			var hobbyList = userdetail.hobby.split(" ");
			$("#hobby").children("span").remove();
			for(var i = 0; i<hobbyList.length; i++){
				$("#hobby").append('<span>'+hobbyList[i]+'</span>');
			}
			$("#signature").text(userdetail.signature);
			$("#addr").text(userdetail.address);
			if(getNowFormatDate()==userdetail.signtime){
				$("#signBtn").attr("disabled",true).text("已签到");
			}else{
				$("#signBtn").attr("disabled",false);
			}
		}else{
			alert(data.resultInfo);
		}
	});
}
//初始化我的大头像
function initUser(){
	user = JSON.parse(getCookie("user"));
	$("#head img").attr("src",getRealPath()+user.head+"");
	showlabel();
}
//hover显示更换头像按钮
function showlabel(){
	$("#head").hover(function(){
		$(this).children("label").stop().animate({"bottom":0},500);
	},function(){
		$(this).children("label").stop().animate({"bottom":-50},500);
	});
}
//修改头像ajax
function updateHead(){
	 var formData = new FormData($( "#uploadForm" )[0]);  
	 formData.append("userDetail_id",JSON.parse(getCookie("user")).id);
     $.ajax({  
         url: '/HyperIT/userdetail/uploadHeadImg',  
         type: 'POST',  
         data: formData,  
         async: false,  
         cache: false,  
         contentType: false,  
         processData: false,  
         success: function (data) {
         	if(data.serviceResult){
         		$("#head img").attr("src",getRealPath()+data.resultParm.headpath+"");
         		var oldUser = JSON.parse(getCookie("user"));
         		delCookie("user");
         		oldUser.head = data.resultParm.headpath;
         		var value = JSON.stringify(oldUser);
         		setCookie("user",value,0);
         		$("#userbox img").attr("src",getRealPath()+data.resultParm.headpath+"");
         		messageTip(data.resultInfo);
         	}else{
         		alert(data.resultInfo)
         	}
	     },  
         error: function (data) {  
             alert(data.resultInfo);  
         }  
   }); 
}
//签到ajax
function sign(){
	var url = "/HyperIT/userdetail/sign";
	var parm = "userdetail_id=" + JSON.parse(getCookie("user")).id;
	$.post(url,parm,function(data){
		if(data.serviceResult){
			$("#signBtn").attr("disabled",true).text("已签到");
			getUserInfo();
			messageTip("签到成功！经验+5 hb+1");
		}else{
			alert(data.resultInfo)
		}
	});
}
//获取当前时间，格式YYYY-MM-DD，用于比较当前时间是否最新签到时间
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = year + seperator1 + month + seperator1 + strDate;
	return currentdate;
}
//修改收货地址ajax
function updateAddr(){
	var url = "/HyperIT/userdetail/updateUserDetail";
	var address = $("#addr_name").val()+" "+$("#addr_phone").val()+" "+$("#addr_addr").val();
	var parm = "id="+user.id+"&address="+address;
	$.post(url,parm,function(data){
		if(data.serviceResult){
			$("#mask").hide();
			$("#addr").text(data.resultParm.userdetail.address);
			messageTip("收货地址更新成功");
		}else{
			alert(data.resultInfo);
		}
	});
}
function toUpdateAddr(){
	showMask();
	$("#addrbox").show();
}
function cancelUpdateAddr(){
	hideMask();
	$("#addrbox").hide();
}
function showMask(){
	$("#mask").show();
}
function hideMask(){
	$("#mask").hide();
}
function toUpdateInfo(){
	showMask();
	$("#infobox").show();
	initInfoForm();
}
function cancelUpdateInfo(){
	hideMask();
	$("#infobox").hide();
}
//获取省份列表
function getPro(){
	var proList = procityjson.provincesList;
	for(var i = 0; i<proList.length; i++){
		$("select#proList").append('<option value="'+proList[i].Name+'">'+proList[i].Name+'</option>')
	}
}
//根据选中的省份，初始化城市列表
function initCity(pro){
	var cityList = procityjson.provincesList[$("#proList option[value='"+pro+"']").index()].Citys;
	for(var i = 0; i<cityList.length; i++){
		$("select#cityList").append('<option value="'+cityList[i].Name+'">'+cityList[i].Name+'</option>')
	}
}
//省份变化出发，刷新city列表
function getCity(){
	initCity("广西壮族自治区");
	$("select#proList").change(function(){
		$("select#cityList").children("option").remove();
		var cityList = procityjson.provincesList[$("#proList option[value='"+$(this).val()+"']").index()].Citys;
		for(var i = 0; i<cityList.length; i++){
			$("select#cityList").append('<option value="'+cityList[i].Name+'">'+cityList[i].Name+'</option>')
		}
	});
}
//初始化个人信息form信息
function initInfoForm(){
	//初始化，先清空option
	$("#posiList option").remove();
	$("#proList option").remove();
	$("#cityList option").remove();
	getPro();
	getCity();
	getPositionList();
	var url = "/HyperIT/userdetail/getUserInfo";
	var parm = "userDetail_id="+user.id;
	$.post(url,parm,function(data){
		if(data.serviceResult){
			var userdetail = data.resultParm.userDetail;
			$("#fName").val(userdetail.name);
			if(!userdetail.sex){
				$("#infobox input[value='male']").attr("checked",true);
			}else{
				$("#infobox input[value='female']").attr("checked",true);
			}
			$("#fSkill").val(userdetail.skill);
			$("#fHobby").val(userdetail.hobby);
			$("#fSignatrue").val(userdetail.signature);
			$("#proList option[value='"+userdetail.city.split(" ")[0]+"']").attr("selected", true);
			initCity(userdetail.city.split(" ")[0]);
			$("#cityList option[value='"+userdetail.city.split(" ")[1]+"']").attr("selected", true);
			$("#posiList option[value='"+userdetail.position_id+"']").attr("selected",true);
		}else{
			alert(data.resultInfo);
		}
	});
}
//获取职位列表ajax
function getPositionList(){
	var url = "/HyperIT/position/findPosition";
	$.get(url,function(data){
		if(data.serviceResult){
			var posiList = data.resultParm.positionlist;
			showPositionList(posiList);
		}else{
			alert(resultInfo);
		}
	});
}
//绘制职位option
function showPositionList(posiList){
	for(var i = 0; i<posiList.length; i++){
		$("#posiList").append('<option value="'+posiList[i].id+'">'+posiList[i].name+'</option>');
	}
}
//提交信息更新个人信息ajax
function updateUserInfo(){
	var sex;
	if($("#infobox input:radio:checked").val()=="male"){
		sex = false;
	}else{
		sex = true;
	}
	var url = "/HyperIT/userdetail/updateUserDetail";
	var parm = "id="+user.id+
			   "&name="+$("#fName").val()+
			   "&sex="+sex+
			   "&city="+$("#proList").val()+" "+$("#cityList").val()+
			   "&position_id="+$("#posiList").val()+
			   "&skill="+$("#fSkill").val()+
			   "&hobby="+$("#fHobby").val()+
			   "&signature="+$("#fSignatrue").val();
	$.post(url,parm,function(data){
		if(data.serviceResult){
			$("#mask").hide();
			$("#infobox").hide();
			getUserInfo();
			delCookie("user");
			var value = JSON.stringify(data.resultParm.userdetail);
			setCookie("user",value);
			messageTip("个人信息修改成功");
		}else{
			alert(data.resultInfo);
		}
	});
}
//获取我发表的文章，并绘制
function getArticle(index){
	var url = "/HyperIT/article/getPersonArticle";
	var parm = "size=5&indexPageNum="+index+"&status=1&id="+user.id;
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var articleList = data.resultParm.article_list;
			showArticle(articleList);
			currentIndex++;
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//获取我的草稿，并绘制
function getArticleDraft(index){
	var url = "/HyperIT/article/getPersonArticle";
	var parm = "size=10&indexPageNum="+index+"&status=0&id="+user.id;
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var articleList = data.resultParm.article_list;
			showArticleDraft(articleList);
			currentIndex++;
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制我发表的文章
function showArticle(articleList){
	for(var i = 0;i<articleList.length; i++){
		$("#myarticle .myarticle-left ul").append('<li id="article_'+articleList[i].id+'">'+
									'<h1>'+articleList[i].title+'</h1>'+
									'<span>发布时间：'+articleList[i].createtime.substr(0,16)+'&nbsp;&nbsp;'+
									'阅读量：'+articleList[i].reading+'次&nbsp;&nbsp;'+
									'打赏：'+articleList[i].reward+'&nbsp;&nbsp;'+
									'收藏：'+articleList[i].collecting+'</span>'+
									'<p>'+articleList[i].info+'</p>'+
									'<a href="../article/articleEdite.html?'+articleList[i].id+'">略作修改</a>'+
									'<a href="../article/thearticle.html?'+articleList[i].id+'">看自己的</a>'+
									'<a href="javascript:void(0)" onclick="delArticle(this)">删除</a>'+
									'</li>');
	}
}
//绘制我的草稿
function showArticleDraft(articleList){
	for(var i = 0;i<articleList.length; i++){
		$("#myarticle .myarticle-left ul").append('<li id="article_'+articleList[i].id+'">'+
									'<h1>'+articleList[i].title+'</h1>'+
									'<span>发布时间：'+articleList[i].createtime.substr(0,16)+'&nbsp;&nbsp;'+
									'阅读量：'+articleList[i].reading+'次&nbsp;&nbsp;'+
									'打赏：'+articleList[i].reward+'&nbsp;&nbsp;'+
									'收藏：'+articleList[i].collecting+'</span>'+
									'<p>'+articleList[i].info+'</p>'+
									'<a href="../article/articleEdite.html?'+articleList[i].id+'">继续编辑</a>'+
									'<a href="javascript:void(0)" onclick="delArticle(this)">删除</a>'+
									'</li>');
	}
}
function getMoreArticle(){
	if($("#myarticle .myarticle-left>span").text()=="我发表的"){
		getArticle(currentIndex);
	}else{
		getArticleDraft(currentIndex);
	}
}
//初始化文章列表
function initArticle(){
	$("#myarticle .myarticle-left>span").text("我发表的");
	currentIndex = 1;//初始化当前文章页为第一页；
	$("#myarticle .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getArticle(currentIndex);//绘制
}
//初始化我的草稿
function initArticleDraft(){
	$("#myarticle .myarticle-left>span").text("草稿箱");
	currentIndex = 1;
	$("#myarticle .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getArticleDraft(currentIndex);//绘制
}
function delArticle(which){
	var con = confirm("确认删除吗？");
	if(con){
		var url = "/HyperIT/article/deleteArticle";
		var parm = "article_id="+$(which).parent().attr("id").split("_")[1];
		$.get(url,parm,function(data){
			if(data.serviceResult){
				$(which).parent().remove();
				messageTip(data.resultInfo);
			}else{
				messageTip(data.resultInfo);
			}
		});
	}else{
		messageTip("已取消删除")
	}
}
//*****************************************************修改密码*******************************//
function updatePassword(){
	if(isPasswordValidate.checkForm()){
		var url = "/HyperIT/user/updatePwd";
		var parm = "id="+thisUser.user_id+"&password="+$("#oldpass").val()+"&new_password="+$("#newpass").val();
		$.post(url,parm,function(data){
			if(data.serviceResult){
				cancelUpdatePassword();
				messageTip(data.resultInfo);
			}else{
				messageTip(data.resultInfo);
			}
		});
	}else{
		isPasswordValidate.showErrors();
	}
}
//修改密码表单验证
function passwordValidate(){
	isPasswordValidate = $("#passwordForm").validate({
		onsubmit: false,
		onkeyup: false, 
		onfocusout: function(element){
			$(element).valid();
	  	},
   		errorPlacement: function(error, element) {  
   			error.appendTo(element.prev());
   		},
		rules:{
			oldpass:{
				required:true,
				minlength:6,
				maxlength:16
			},
			newpass:{
				required:true,
				minlength:6,
				maxlength:16
			},
			confirmpass:{
				required:true,
				equalTo:"#newpass"
			}
		},
		messages:{
			oldpass:{
				required:"请输入旧密码！",
				minlength:"密码不能小于6个字符！",
				maxlength:"密码不能多于16个字符！"
			},
			newpass:{
				required:"请输入新密码！",
				minlength:"密码不能小于6个字符！",
				maxlength:"密码不能多于16个字符！"
			},
			confirmpass:{
				required:"请输入确认密码！",
				equalTo:"确认密码与新密码不一致！"
			}
		}
	});
}
function cancelUpdatePassword(){
	$("#mask").hide();
	$("#passwordbox").hide();
	$("#passwordForm input:password").val("");
}
function toUpdatePassword(){
	passwordValidate();
	$("#mask").show();
	$("#passwordbox").show();
	$("#passwordForm input:password").val("");
}
//*************************************************关注***********************//
//获取我的关注ajax
function getFollow(){
	var url ="/HyperIT/blog/getFollow";
	var parm = "userdetail_id="+thisUser.id;
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var followList = data.resultParm.ud_list;
			showFollow(followList);
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制我关注的
function showFollow(followList){
	$("#follow>ul").children().remove();
	if(followList.length==0){
		messageTip("你没有关注他人哦！");
	}
	for(var i = 0; i<followList.length; i++){
		$("#follow>ul").append('<li id="blog_'+followList[i].id+'">'+
									'<a href="theblog.html?'+followList[i].id+'"><img src="../..'+followList[i].head+'"/></a>'+
								'</li>');
	}
}
//hover显示详细信息
function showDetail(){
	
}
//**************************************************私信************************************//
//獲取私信ajax
function getSixin(index){
	var url = "/HyperIT/blog/getComment";
	var parm = "size=6&indexPageNum="+index+"&target_id="+thisUser.id+"&type=3";
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var sixinlist = data.resultParm.getcomment;
			showSixin(sixinlist);
			currentIndex++;
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制私信
function showSixin(sixinList){
	for(var i = 0; i<sixinList.length; i++){
		$("#sixin ul").append('<li id="comment_'+sixinList[i].comment.id+'">'+
									'<span>'+sixinList[i].comment.createtime.substr(0,16)+'</span>来自 '+
									'<a href="theblog.html?'+sixinList[i].userdetail.id+'">'+
									'<span>'+sixinList[i].userdetail.name+'</span></a>'+
									'<p>'+sixinList[i].comment.content+'</p>'+
									'<div class="action-box">'+
										'<a href="javascript:void(0)" onclick="delSixin(this)">删除</a>'+
										'<a href="javascript:void(0)" onclick="toSixin('+sixinList[i].userdetail.id+')">回复</a>'+
									'</div>'+
							   '</li>');
	}
}
//删除私信
function delSixin(which){
	var con = confirm("确认删除？");
	if(con){
		var url = "/HyperIT/blog/deleteComment";
		var parm = "userdetail_id="+thisUser.id+"&comment_id="+$(which).parent().parent().attr("id").split("_")[1];
			$.post(url,parm,function(data){
			if(data.serviceResult){
				$(which).parent().parent().remove();
				messageTip(data.resultInfo)
			}else{
				messageTip(data.resultInfo);
			}
		});
	}else{
		return;
	}
}
function getMoreSixin(){
	getSixin(currentIndex);
}
function initSixin(){
	currentIndex=1;
	$("#sixin ul").children("li").remove();
	getSixin(currentIndex);
}
//************************************************问答部分*******************************//
//点击我的问答，初始化问答选择卡
function initaq(){
	//进入清空li
	$("#aq ul").children("li").remove();
	//问答页置1
	currentIndex = 1;
	getaq(currentIndex);
}
//获取问答ajax
function getaq(index){
	var url = "/HyperIT/question/getPersonQuestion";
	var parm = "userdetail_id="+thisUser.id+"&size=5&indexPageNum="+index;
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var aqList = data.resultParm.question_user_list;
			showaq(aqList);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制aq
function showaq(aqList){
	var isAccept;
	for(var i = 0; i<aqList.length; i++){
		if (aqList[i].accept) {
			isAccept = "已采纳";
		} else{
			isAccept = "未采纳";
		}
		$("#aq ul").append('<li id="aq_'+aqList[i].id+'">'+
								'<h1>'+aqList[i].title+'</h1>'+
								'<span>提问时间：'+aqList[i].createtime.substr(0,16)+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>'+aqList[i].answer+'条回答</span>&nbsp;&nbsp;&nbsp;'+
								'<span>'+isAccept+'</span>&nbsp;&nbsp;&nbsp;'+
								'<a href="../aq/theaq.html?'+aqList[i].id+'">查看回答</a>'+
								'<a href="javascript:void(0)" onclick="delaq(this)">删除</a>'+
							'</li>');
	}
}
//更多
function getMoreAq(){
	getaq(currentIndex);
}
//删除回答
function delaq(which){
	var con = confirm("确定删除？");
	if (con) {
		var url = "/HyperIT/question/deleteQuestion";
		var parm = "userdetail_id="+thisUser.id+"&question_id="+$(which).parent().attr("id").split("_")[1];
		$.post(url,parm,function(data){
			if (data.serviceResult) {
				messageTip(data.resultInfo);
				$(which).parent().remove();
			} else{
				messageTip(data.resultInfo);
			}
		});
	} else{
		return;
	}
}
//********************************************************随笔****************************//
//初始化随笔
function initNote(){
	//进入清空li
	$("#note ul").children("li").remove();
	//问答页置1
	currentIndex = 1;
	getNote(currentIndex);
}
//获取随笔ajax
function getNote(index){
	var url = "/HyperIT/note/findPersonNote";
	var parm = "size=10&indexPageNum="+index+"&userdetail_id="+thisUser.id+"&status=0";
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var noteList = data.resultParm.note_list;
			showNote(noteList);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制note
function showNote(notelist){
	for(var i = 0; i<notelist.length; i++){
		$("#note ul").append('<li id="note_'+notelist[i].id+'">'+
								'<h1>'+notelist[i].title+'</h1>'+
								'<span>发布时间：'+notelist[i].createtime.substr(0,16)+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>阅读量：'+notelist[i].reading+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>收藏：'+notelist[i].collecting+'</span>&nbsp;&nbsp;&nbsp;'+
								'<a href="../note/editeNote.html?'+notelist[i].id+'">略作修改</a>'+
								'<a href="../note/thenote.html?'+notelist[i].id+'">看自己的</a>'+
								'<a href="javascript:void(0)" onclick="delNote(this)">删除</a>'+
							'</li>');
	}
}
//绘制notedraft
function showNoteDraft(notelist){
	for(var i = 0; i<notelist.length; i++){
		$("#note ul").append('<li id="note_'+notelist[i].id+'">'+
								'<h1>'+notelist[i].title+'</h1>'+
								'<span>发布时间：'+notelist[i].createtime.substr(0,16)+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>阅读量：'+notelist[i].reading+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>收藏：'+notelist[i].collecting+'</span>&nbsp;&nbsp;&nbsp;'+
								'<a href="../note/editeNote.html?'+notelist[i].id+'">略作修改</a>'+
								'<a href="javascript:void(0)" onclick="delNote(this)">删除</a>'+
							'</li>');
	}
}
function getMoreNote(){
	if($("#note .myarticle-left>span").text()=="我发表的"){
		getNote(currentIndex);
	}else{
		getNoteDraft(currentIndex);
	}
}
//删除回答
function delNote(which){
	var con = confirm("确定删除？");
	if (con) {
		var url = "/HyperIT/note/deleteNote";
		var parm = "note_id="+$(which).parent().attr("id").split("_")[1]+"&userdetail_id="+thisUser.id;
		$.post(url,parm,function(data){
			if (data.serviceResult) {
				$(which).parent().remove();
				messageTip(data.resultInfo);
			} else{
				messageTip(data.resultInfo);
			}
		});
	} else{
		return;
	}
}
//初始化我的草稿
function initNoteDraft(){
	$("#note .myarticle-left>span").text("草稿箱");
	currentIndex = 1;
	$("#note .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getNoteDraft(currentIndex);//绘制
}
//初始化我发表的
function initNote(){
	$("#note .myarticle-left>span").text("我发表的");
	currentIndex = 1;//初始化当前文章页为第一页；
	$("#note .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getNote(currentIndex);//绘制
}
//获取我的草稿，并绘制
function getNoteDraft(index){
	var url = "/HyperIT/note/findPersonNote";
	var parm = "size=10&indexPageNum="+index+"&userdetail_id="+thisUser.id+"&status=1";
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var noteList = data.resultParm.note_list;
			showNoteDraft(noteList);
			currentIndex++;
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//*****************************************留言************************************//
//获取留言
function getLeaveWord(index){
	var url = "/HyperIT/blog/getComment";
	var parm = "size=20&indexPageNum="+index+"&target_id="+thisUser.id+"&type=2";
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var lwlist = data.resultParm.getcomment;
			showLeaveWord(lwlist);
			currentIndex++;
		}else{
			messageTip(data.resultInfo);
		}
	});
}
//showlist
function showLeaveWord(lwlist){
	for(var i = 0;i<lwlist.length; i++){
		$("#leaveword ul").append('<li>'+
									'<span>'+lwlist[i].comment.createtime.substr(0,16)+'</span>'+
									'<a href="../blog/theblog.html?'+lwlist[i].userdetail.id+'">'+
									'<img src="../..'+lwlist[i].userdetail.head+'"/></a>'+
									'<p>'+lwlist[i].comment.content+'</p>'+
								  '</li>');
	}
}
//init
function initLeaveWord(){
	$("#leaveword ul").children("li").remove();
	currentIndex = 1;
	getLeaveWord(currentIndex);
}
//getmore
function getMoreLeaveWord(){
	getLeaveWord(currentIndex);
}
//*******************************************收藏collecttion*****************************************************//
function initColletionArticle(){
	$("#collection .myarticle-left>span").text("文章收藏");
	currentIndex = 1;
	$("#collection .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getCollectionArticle(currentIndex);//绘制
}
function initCollectionNote(){
	$("#collection .myarticle-left>span").text("随笔收藏");
	currentIndex = 1;
	$("#collection .myarticle-left ul").children("li").remove();//清楚ul中的所有li
	getCollectionNote(currentIndex);//绘制
}

function getCollectionArticle(index){
	var url = "/HyperIT/blog/getCollect";
	var parm = "size=10&indexPageNum="+index+"&userdetail_id="+thisUser.id+"&type=0";
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var collectList = data.resultParm.collect_list;
			showCollectionArticle(collectList);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
function getCollectionNote(index){
	var url = "/HyperIT/blog/getCollect";
	var parm = "size=10&indexPageNum="+index+"&userdetail_id="+thisUser.id+"&type=1";
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var collectList = data.resultParm.collect_list;
			showCollectionNote(collectList);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
function showCollectionArticle(collectList){
	for(var i = 0;i<collectList.length; i++){
		$("#collection .myarticle-left ul").append('<li id="collection_'+collectList[i].id+'">'+
									'<h1>'+collectList[i].title+'</h1>'+
									'<span>发布时间：'+collectList[i].createtime.substr(0,16)+'&nbsp;&nbsp;'+
									'阅读量：'+collectList[i].reading+'次&nbsp;&nbsp;'+
									'打赏：'+collectList[i].reward+'&nbsp;&nbsp;'+
									'收藏：'+collectList[i].collecting+'</span>'+
									'<p>'+collectList[i].info+'</p>'+
									'<a href="../article/thearticle.html?'+collectList[i].id+'">前往</a>'+
									'<a href="javascript:void(0)" onclick="delCollection(this,0)">取消收藏</a>'+
									'</li>');
	}
}
function showCollectionNote(collectList){
	for(var i = 0; i<collectList.length; i++){
		$("#collection .myarticle-left ul").append('<li id="collection_'+collectList[i].id+'">'+
								'<h1>'+collectList[i].title+'</h1>'+
								'<span>发布时间：'+collectList[i].createtime.substr(0,16)+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>阅读量：'+collectList[i].reading+'</span>&nbsp;&nbsp;&nbsp;'+
								'<span>收藏：'+collectList[i].collecting+'</span>&nbsp;&nbsp;&nbsp;'+
								'<a href="../note/thenote.html?'+collectList[i].id+'">前往</a>'+
								'<a href="javascript:void(0)" onclick="delCollection(this,1)">取消删除</a>'+
							'</li>');
	}
}
function getMoreCollection(){
	if($("#collection .myarticle-left>span").text()=="文章收藏"){
		getCollectionArticle(currentIndex);
	}else{
		getCollectionNote(currentIndex);
	}
}
function delCollection(which,type){
	var con = confirm("取消收藏？");
	if (con) {
		var url = "/HyperIT/blog/deleteCollect";
		var parm = "userdetail_id="+thisUser.id+"&id="+$(which).parent().attr("id").split("_")[1]+"&type="+type;
		$.post(url,parm,function(data){
			if (data.serviceResult) {
				$(which).parent().remove();
				messageTip(data.resultInfo);
			} else{
				messageTip(data.resultInfo);
			}
		});
	} else{
		return;
	}
}
